/*
 * #%L
 * SwiftUIDataAccessLayer
 * $Id:$
 * $HeadURL:$
 * %%
 * Copyright (C) 2011 - 2012 Linkwithweb
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 3 of the 
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public 
 * License along with this program.  If not, see
 * <http://www.gnu.org/licenses/gpl-3.0.html>.
 * #L%
 */
package com.linkwithweb.products.swiftui.service;

import java.io.OutputStream;
import java.sql.ResultSet;
import java.util.List;
import java.util.Map;

import com.linkwithweb.products.swiftui.context.DBUpdateStatement;
import com.linkwithweb.products.swiftui.context.ExcelFile;
import com.linkwithweb.products.swiftui.context.QueryContext;
import com.linkwithweb.products.swiftui.dao.PlatformDAO;
import com.linkwithweb.products.swiftui.dataobject.FrameworkBackup;
import com.linkwithweb.products.swiftui.dataobject.FrameworkEvent;
import com.linkwithweb.products.swiftui.dataobject.FrameworkEventScheduler;
import com.linkwithweb.products.swiftui.dataobject.FrameworkForm;
import com.linkwithweb.products.swiftui.dataobject.FrameworkLOVValue;
import com.linkwithweb.products.swiftui.dataobject.FrameworkMenu;
import com.linkwithweb.products.swiftui.dataobject.FrameworkTextReport;
import com.linkwithweb.products.swiftui.dataobject.FrameworkTransaction;
import com.linkwithweb.products.swiftui.dataobject.FrameworkUpload;
import com.linkwithweb.products.swiftui.dataobject.FrameworkUser;
import com.linkwithweb.products.swiftui.dataobject.FrameworkWorkflow;
import com.linkwithweb.products.swiftui.spring.jdbc.DatabaseResult;
import com.linkwithweb.products.swiftui.spring.jdbc.MapObject;

/**
 * @author ashwin
 * 
 */
public interface PlatformService {

	public PlatformDAO getPlatformDAO();
	/**
	 * 
	 * @param sql
	 * @param isFrameworkDB
	 * @return
	 */
	public DatabaseResult loadResult(String sql, String dataSourceTemplate);

	/**
	 * 
	 * @param sql
	 * @param isFrameworkDB
	 * @param values
	 * @param fromIndex
	 * @param toIndex
	 * @return
	 */
	public DatabaseResult loadResult(String sql, String dataSourceTemplate, List values, long fromIndex, long toIndex);

	/**
	 * 
	 * @param sql
	 * @param isFrameworkDB
	 * @param values
	 * @return
	 */
	public DatabaseResult loadResult(String sql, String dataSourceTemplate, List values);

	/**
	 * 
	 * @param sql
	 * @param isFrameworkDB
	 * @param values
	 * @return
	 */
	public int queryForInt(String sql, String dataSourceTemplate, List values);

	/**
	 * 
	 * @param isFrameworkDB
	 * @return
	 */
	public List<String> getTableNames(String dataSourceTemplate);

	/**
	 * 
	 * @param queryContext
	 * @param isFrameworkDB
	 * @return
	 */
	public DatabaseResult loadResult(QueryContext queryContext, String dataSourceTemplate);

	/**
	 * @param sql
	 * @param isFrameworkDB
	 * @param args
	 */
	public void update(String sql, String dataSourceTemplate, Object[] args);

	/**
	 * @param sql
	 * @param isFrameworkDB
	 * @param args
	 * @return
	 */
	public Long saveAndGetKey(final String sql, String dataSourceTemplate, final Object[] args);

	/**
	 * Loads Form metadata
	 * 
	 * @param id
	 * @return
	 */
	public FrameworkForm loadForm(String id);

	/**
	 * Loads Report Metadata
	 * 
	 * @param id
	 * @return
	 */
	public FrameworkTextReport loadReport(String id);
	
	/**
	 * @param reportSQL
	 * @return
	 */
	public FrameworkTextReport loadReportFromSQL(String reportSQL);

	/**
	 * @param reportObject
	 * @return
	 */
	public DatabaseResult loadReportData(FrameworkTextReport reportObject);

	public DatabaseResult loadReportDataFromSQL(String reportSQL,FrameworkTextReport reportObject);
	/**
	 * @return
	 */
	public List<FrameworkMenu> loadTreeMenu();

	/**
	 * @param reportObject
	 */
	public void insertRecordForReport(FrameworkTextReport reportObject);

	/**
	 * @param reportObject
	 */
	public void updateRecordForReport(FrameworkTextReport reportObject);

	/**
	 * @param reportObject
	 */
	public void deleteRecordInReport(FrameworkTextReport reportObject);

	/**
	 * @param reportObject
	 * @return
	 */
	public List<FrameworkLOVValue> loadLovValuesData(FrameworkTextReport reportObject);

	/**
	 * @param sql
	 * @param isFrameworkDB
	 * @return
	 */
	public ResultSet getResultSet(String sql, String dataSourceTemplate);

	/**
	 * @return
	 */
	public boolean isUserValid();

	/**
	 * @param excelFile
	 */
	public void loadExcelFile(ExcelFile excelFile);

	/**
	 * @param dbUrl
	 * @param dbType
	 * @param username
	 * @param password
	 */
	public void loadAndStoreDataSource(String dbUrl, String dbType, String username, String password);

	/**
	 * 
	 */
	public void connectAndGenerateReports(ExcelFile excelFile);

	/**
	 * @param userName
	 * @param password
	 * @return
	 */
	public FrameworkUser loadUser(String userName, String password);

	public FrameworkWorkflow loadWorkflowForTable(String tableId);

	public FrameworkTransaction loadLastWorkflowTransaction(String tableId);

	public List<FrameworkTransaction> loadWorkflowTasks();

	public FrameworkWorkflow loadWorkflowForTransaction(FrameworkTransaction transaction);

	public void addNewTransactionForTable(DBUpdateStatement stmt);

	public void changeTransactionStatus(FrameworkTransaction transaction, String newApprovalStatus);

	public FrameworkTransaction loadWorkflowTransaction(String transactionId);

	public void executeScript(String sqlScriptPath, String dataSourceName);

	public void generateReport(String reportName, String sql, Map<String, Object> parameters, OutputStream out);

	public void uploadFile(FrameworkUpload upload);
	
	public List<FrameworkUpload> getFilesByTag(String tagName);
	/**
	 * @param schedulerId
	 * @param arguments 
	 * @return
	 */
	public List<FrameworkEvent> loadEvents(String schedulerId, Map<String, String> arguments);

	/**
	 * @param frameworkEvent
	 */
	public void saveOrUpdateEvent(FrameworkEvent frameworkEvent);

	/**
	 * @param schedulerId
	 * @param uniqueKey
	 * @return
	 */
	public FrameworkEvent loadEvent(String schedulerId, int uniqueKey);

	/**
	 * @param frameworkEventScheduler
	 */
	public void saveOrUpdateEventScheduler(FrameworkEventScheduler frameworkEventScheduler);

	/**
	 * @param schedulerId
	 * @return
	 */
	public FrameworkEventScheduler loadEventScheduler(String schedulerId);
	/**
	 * @param event
	 */
	public void deleteEvent(FrameworkEvent event);
	
	
	/**
	 * @param frameworkEventScheduler
	 * @return
	 */
	public List<MapObject> getResourcesForScheduler(FrameworkEventScheduler frameworkEventScheduler,Map<String,Object> arguments);
	
	/**
	 * @param backup
	 */
	public void saveBackupDetails(FrameworkBackup backup);
	/**
	 * @param backupId
	 * @return
	 */
	public FrameworkBackup loadBackupById(String backupId);
	/**
	 * @return
	 */
	public List<FrameworkBackup> loadBackups();
}
